package com.xh.bussiness.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.system.bean.dto.ParentBean;
import com.xh.bussiness.system.bean.request.ParentRequest;
import com.xh.bussiness.system.dao.ParentMapper;
import com.xh.bussiness.system.model.Parent;
import com.xh.bussiness.system.service.IParentService;
import com.xh.core.bean.XhPage;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParentServiceImpl extends BaseServiceImpl<ParentMapper,Parent> implements IParentService {
    @Override
    public Parent getParentByUserId(String userId) {
        QueryWrapper qw=new QueryWrapper<Parent>();
        qw.in("user_id",userId);
        return this.dao.selectOne(qw);
    }

    @Override
    public XhPage queryParentPage(XhPage page, ParentRequest bean) {
        QueryWrapper qw=new QueryWrapper<Parent>();
        //拼装条件
        qw=prepareParams(bean, qw);
        return (XhPage) this.selectPage(page,qw,ParentBean.class);
    }

    @Override
    public List queryParent(ParentRequest bean) {
        QueryWrapper qw=new QueryWrapper<Parent>();
        //拼装条件
        qw=prepareParams(bean, qw);
        return this.selectList(qw, ParentBean.class);
    }

    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(ParentRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }

        return qw;
    }
}
